(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.popup.serviceCmpntController', viewController);
	viewController.$inject = [ '$scope', '$q', '$uibModalInstance', 'Constants', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig', 'validatorConfig', 'authService' ];
	function viewController($scope, $q, $uibModalInstance, Constants, dialogsModule, gridService, modalService, layoutConfig, validatorConfig, authService) {
		var ctrl = this, params;
		ctrl.dialogsModule = dialogsModule;
		params = ctrl.dialogsModule.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
		ctrl.init = function() {
			ctrl.innerGridOptionsCmpntRight = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.serviceCmpntRight.tableConfigs.table);
			ctrl.innerGridOptionsCmpntRight.data = 'vm.serviceCmpnt.rights';
			ctrl.innerGridOptionsCmpntEvent = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.serviceCmpntEvent.tableConfigs.table);
			ctrl.innerGridOptionsCmpntEvent.data = 'vm.serviceCmpnt.events';
			return authService.viewCmpnt(params).then(function(response) {
				ctrl.serviceCmpnt = response.data || params;
				ctrl.serviceCmpnt.events = ctrl.serviceCmpnt.serviceCmpntEvents;
				ctrl.serviceCmpnt.rights = ctrl.serviceCmpnt.serviceCmpntRights;
			}, angular.noop);
		};
	}
})(angular);